home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Db C Library Procedures Db
-
-
-
- _________________________________________________________________
-
- NNAAMMEE
- Db - manipulate simple database files
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<ddbb..hh>>
-
- int
- DDbb__WWrriitteeEEnnttrryy(_f_i_l_e, _b_u_f_f_e_r, _i_n_d_e_x, _s_i_z_e, _l_o_c_k_H_o_w)
-
- int
- DDbb__RReeaaddEEnnttrryy(_f_i_l_e, _b_u_f_f_e_r, _i_n_d_e_x, _s_i_z_e, _l_o_c_k_H_o_w)
-
- int
- DDbb__OOppeenn(_f_i_l_e, _s_i_z_e, _h_a_n_d_l_e_P_t_r, _w_r_i_t_i_n_g, _l_o_c_k_W_h_e_n, _l_o_c_k_H_o_w, _n_u_m_B_u_f)
-
- int
- DDbb__PPuutt(_h_a_n_d_l_e_P_t_r, _b_u_f_f_e_r, _i_n_d_e_x)
-
- int
- DDbb__GGeett(_h_a_n_d_l_e_P_t_r, _b_u_f_f_e_r, _i_n_d_e_x)
-
- int
- DDbb__CClloossee(_h_a_n_d_l_e_P_t_r)
-
-
- AARRGGUUMMEENNTTSS
- char *_f_i_l_e (in) The name of a database
- file on which to per-
- form operations.
-
- char *_b_u_f_f_e_r (in/out) A pointer to the area
- from which or to which
- to transfer the record.
-
- int _i_n_d_e_x (out) Which record to access
- in a database opera-
- tion.
-
- int _s_i_z_e (in) The size of a record.
-
- Db_LockHow _l_o_c_k_H_o_w (in) Method to use when
- locking the database.
-
- Db_Handle *_h_a_n_d_l_e_P_t_r (in/out) A pointer to a ``data-
- base handle''.
-
- int _w_r_i_t_i_n_g (in) If non-zero, the data-
- base file is opened in
- write-only mode, other-
- wise in read-only mode.
-
-
-
- Sprite v.1.0 Printed: February 20, 1989 1
-
-
-
-
-
-
- Db C Library Procedures Db
-
-
-
- Db_LockWhen _l_o_c_k_W_h_e_n (in) Determines when to lock
- the database for long-
- term accesses.
-
- int _n_u_m_B_u_f (in) Number of records to
- buffer when reading
- from database.
-
- _________________________________________________________________
-
- DDEESSCCRRIIPPTTIIOONN
- These functions provide shared access to files containing
- arbitrary numbers of fixed-length records. There are two
- ways to access the files. The simplest way to access a
- database file is to use DDbb__WWrriitteeEEnnttrryy(()) and DDbb__RReeaaddEEnnttrryy(())
- to open the file, access a record, and close the file again.
- An alternative method is to use DDbb__OOppeenn(()) to obtain a hhaannddllee
- for the file, use DDbb__PPuutt(()) or DDbb__GGeett(()) to write or read
- entries, respectively, and use Db_Close() to close the file
- when it is no longer needed. In this case, the _n_u_m_B_u_f argu-
- ment is used to specify how many records to buffer inter-
- nally when doing reads (it must be specified as 0 for
- writes).
-
- The Db library provides a simple locking facility to allow
- shared access to files, built on top of the fflloocckk(()) system
- call. Database files can be accessed without using locks,
- or using the standard fflloocckk(()) call in blocking or non-
- blocking mode. Unfortunately, hosts can hold locks when
- they crash, so a program that performs a blocking lock could
- wait indefinitely for a lock if no additional mechanism is
- used. The Db library allows locks to time out, and it can
- optionally break a lock if the lock times out. The time-out
- period is currently fixed. The different options are speci-
- fied by the Db_LockHow type:
-
- typedef enum {
- DDBB__LLOOCCKK__NNOO__BBLLOOCCKK, /* return immediately with error */
- DDBB__LLOOCCKK__PPOOLLLL, /* poll the lock; time out if necessary */
- DDBB__LLOOCCKK__WWAAIITT, /* wait indefinitely */
- DDBB__LLOOCCKK__BBRREEAAKK, /* poll, plus break the lock if needed */
- DDBB__LLOOCCKK__NNOONNEE, /* do not lock the file at all */
- } Db_LockHow;
-
- The DDbb__WWrriitteeEEnnttrryy(()) and DDbb__RReeaaddEEnnttrryy(()) procedures take a
- Db_LockHow parameter to determine how to lock the database
- file the one time it is accessed. In addition to a Db_Lock
- parameter, DDbb__OOppeenn(()) takes a Db_LockWhen argument to specify
- when to perform the lock. Generally, when a file is going
- to be read or written sequentially, one would like to lock
- it before starting to do I/O and unlock it after finishing.
- If a file is going to be accessed repeatedly over a long
- period of time, however, it should be opened once but locked
- only during each access. These options are DDBB__LLOOCCKK__OOPPEENN and
-
-
-
- Sprite v.1.0 Printed: February 20, 1989 2
-
-
-
-
-
-
- Db C Library Procedures Db
-
-
-
- DDBB__LLOOCCKK__AACCCCEESSSS, respectively. If the file is never to be
- locked, then the Db_LockWhen argument may be specified as
- DDBB__LLOOCCKK__NNEEVVEERR or the Db_LockHow argument may be specified as
- DDBB__LLOOCCKK__NNOONNEE.
-
- DDbb__WWrriitteeEEnnttrryy(()) and DDbb__RReeaaddEEnnttrryy(()) provide access to a sin-
- gle record. They take the _f_i_l_e_n_a_m_e to access; an _i_n_d_e_x into
- the file, the _s_i_z_e of a record; a pointer to a data _b_u_f_f_e_r;
- and the method of locking the database, _l_o_c_k_H_o_w. All
- records must have the same size. The index is zero-based,
- so _i_n_d_e_x 0 refers to the first record in the file.
-
- DDbb__OOppeenn(()) takes the same _f_i_l_e, _s_i_z_e, and _l_o_c_k_H_o_w arguments
- as DDbb__WWrriitteeEEnnttrryy(()) and DDbb__RReeaaddEEnnttrryy(()). It also takes an
- argument, _w_r_i_t_i_n_g, which indicates whether access will be
- writing (1) or reading (0); and another argument, _n_u_m_B_u_f,
- which specifies how many records to read from the file at
- once when doing reads. The _l_o_c_k_W_h_e_n argument is described
- above; it indicates whether locking should be done for each
- access or at the time the file is opened. DDbb__OOppeenn(()) returns
- a database handle in *_h_a_n_d_l_e_P_t_r. The storage for the handle
- must be allocated by the caller of DDbb__OOppeenn(()). A pointer to
- the handle must be used in later calls to DDbb__PPuutt(()),
- DDbb__GGeett(()), or DDbb__CClloossee(()).
-
- DDbb__PPuutt(()) and DDbb__GGeett(()) are analogous to DDbb__WWrriitteeEEnnttrryy(()) and
- DDbb__RReeaaddEEnnttrryy(()). They are used in cases when the database
- file is opened by DDbb__OOppeenn(()), for use over an extended period
- of time. The _h_a_n_d_l_e_P_t_r argument must be a handle returned
- by DDbb__OOppeenn(()). The _b_u_f_f_e_r must be a pointer to an area of
- the size specified in the call to DDbb__OOppeenn(()). The _i_n_d_e_x is
- an integer: if non-negative, it specifies a record number,
- like in calls to DDbb__WWrriitteeEEnnttrryy(()) and DDbb__RReeaaddEEnnttrryy(()). If
- _i_n_d_e_x is -1, it specifies that the access should be sequen-
- tial: the record to be operated upon should be the one
- immediately following the last record read or written. If
- DDbb__PPuutt(()) or DDbb__GGeett(()) is called for the first time with an
- _i_n_d_e_x of -1, the first record is written or read.
-
- DDbb__CClloossee(()) closes a file that was opened with DDbb__OOppeenn(()).
- _H_a_n_d_l_e_P_t_r must point to a handle that was initialized by
- DDbb__OOppeenn(()).
-
- DDIIAAGGNNOOSSTTIICCSS
- All routines return 0 if they complete successfully. Upon
- error, they return -1 and the _e_r_r_n_o variable contains addi-
- tional information about what error occurred.
-
- KKEEYYWWOORRDDSS
- database, data base, lock, record, handle
-
-
-
-
-
- Sprite v.1.0 Printed: February 20, 1989 3
-
-
-
-
-
-
- Db C Library Procedures Db
-
-
-
- SSEEEE AALLSSOO
- mig, ulog, flock, dbm
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sprite v.1.0 Printed: February 20, 1989 4
-
-
-
-